package itheima.jdk8.methodreference;


import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author Euphy
 *description：compare的各种方法
 */
public class MethodReferenceTest {

    public String getString(Supplier<String> supplier) {
        return supplier.get() + "test";
    }

    public String getString2(String str, Function<String, String> function) {
        return function.apply(str);
    }


    public static void main(String[] args) {
        Student student1 = new Student("zhangsan", 10);
        Student student2 = new Student("lisi", 90);
        Student student3 = new Student("wangwu", 50);
        Student student4 = new Student("zhaoliu", 40);

        List<Student> students = Arrays.asList(student1, student2, student3, student4);
        students.sort(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //Student.compareStudentByScore(o1, o2);
                return o2.compareByScore(o1);
            }
        });
        students.forEach(student -> System.out.println("00001====>"+student.getScore()));

        students.sort((studentParam1, studentParam2) -> Student.compareStudentByScore(studentParam1, studentParam2));
        students.forEach(student -> System.out.println("000002=====>"+student.getScore()));

        System.out.println("-------");


        /**
         * 这个写法真的是无解了，这个是方法引用？
         * 1.隐藏了studentParam1和studentParam2 两个参数
         * 这个方法其他情况下是不行的，只是因为这里有了static 的比较方法而已！！
         */
        students.sort(Student::compareStudentByScore);
        students.forEach(student -> System.out.println(student.getScore()));

//        students.sort((studentParam1, studentParam2) ->
//                Student.compareStudentByName(studentParam1, studentParam2));
//        students.forEach(student -> System.out.println(student.getName()));

//        students.sort(Student::compareStudentByName);
//        students.forEach(student -> System.out.println(student.getName()));

        StudentComparator studentComparator = new StudentComparator();

        students.sort(new Comparator<Student>() {
            @Override
            public int compare(Student studentParam1, Student studentParam2) {
                return studentComparator.compareStudentByScore(studentParam1, studentParam2);
            }
        });
        students.forEach(student -> System.out.println(student.getScore()));

//        students.sort(studentComparator::compareStudentByScore);
//        students.forEach(student -> System.out.println(student.getScore()));

//        students.sort((studentParam1, studentParam2) ->
//                studentComparator.compareStudentByName(studentParam1, studentParam2));
//        students.forEach(student -> System.out.println(student.getName()));

//        students.sort(studentComparator::compareStudentByName);
//        students.forEach(student -> System.out.println(student.getName()));

//        students.sort(Student::compareByScore);
//        students.forEach(student -> System.out.println(student.getScore()));

//        students.sort(Student::compareByName);
//        students.forEach(student -> System.out.println(student.getName()));


//        List<String> cities = Arrays.asList("qingdao", "chongqing", "tianjin", "beijing");

//        Collections.sort(cities, (city1, city2) -> city1.compareToIgnoreCase(city2));
//        cities.forEach(city -> System.out.println(city));

//        Collections.sort(cities, String::compareToIgnoreCase);
//        cities.forEach(System.out::println);

      /*  MethodReferenceTest methodReferenceTest = new MethodReferenceTest();
        System.out.println(methodReferenceTest.getString(String::new));
        System.out.println(methodReferenceTest.getString2("hello", String::new));*/

    }
}
